package direct;

import com.rabbitmq.client.*;
import utils.RabbitMQUtils;

import java.io.IOException;

public class Customer2 {
    public static void main(String[] args) throws IOException {
        Connection connection = RabbitMQUtils.getConnection();
        Channel channel = connection.createChannel();

        String exchangeName = "logs_direct";
        channel.exchangeDeclare(exchangeName, "direct");

        String routingKey1 = "info";
        String routingKey2 = "error";
        String routingKey3 = "warning";
        String queue = channel.queueDeclare().getQueue();
        channel.queueBind(queue, exchangeName, routingKey1);
        channel.queueBind(queue, exchangeName, routingKey2);
        channel.queueBind(queue, exchangeName, routingKey3);

        channel.basicConsume(queue, true, new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者1：" + new String(body));
            }
        });


    }
}
